package com.wz.project.cxtj.viewstockstatistic.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.cxtj.viewstockstatistic.domain.ViewStockStatistics;
import com.wz.project.cxtj.viewstockstatistic.service.IViewStockStatisticsService;
import com.wz.project.mydo.domain.MydoJobDetail;
import com.wz.project.stock.domain.BasStock;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存统计Controller
 * 
 * @author wz
 * @date 2022-05-18
 */
@Controller
@RequestMapping("/search/viewstockstatistic")
public class ViewStockStatisticsController extends BaseController
{
    private String prefix = "cxtj/viewstockstatistic";

    private String barcode1 = "";

    @Autowired
    private IViewStockStatisticsService viewStockStatisticsService;

    /**
     * 跳转库存统计页面
     */
    @RequiresPermissions("search:viewstockstatistic:view")
    @GetMapping()
    public String viewstockstatistic()
    {
        return prefix + "/viewstockstatistic";
    }

    /**
     * 查询库存统计母列表
     */
//    @RequiresPermissions("search:viewstockstatistic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewStockStatistics viewStockStatistics)
    {
        startPage();
        List<ViewStockStatistics> list = viewStockStatisticsService.selectStockCountList(viewStockStatistics);
        return getDataTable(list);
    }
    /**
     *
     * 查询库存统计子列表
     */
    @RequestMapping("/stockZList")
    @ResponseBody
    public TableDataInfo list(String productId)
    {
        startPage();
        ViewStockStatistics viewStockStatistics = new ViewStockStatistics();
        viewStockStatistics.setProductId(productId);
        List<ViewStockStatistics> viewStockStatistics1 = viewStockStatisticsService.selectViewStockStatisticsList(viewStockStatistics);
        return getDataTable( viewStockStatisticsService.selectViewStockStatisticsList(viewStockStatistics));
    }
    /**
     * 跳转小窗口页面
     */
    @GetMapping("/selectStock")
    public String selectStock(String barcode) {
        barcode1=barcode;
        return prefix + "/selectStock";
    }
    /**
     * 查询库存统计详细列表
     */
    @RequestMapping("/selectStockList")
    @ResponseBody
    public TableDataInfo selectStockList(BasStock basStock)
    {
        startPage();
        basStock.setBarcode(barcode1);
        List<BasStock> basStocks = viewStockStatisticsService.selectStockList(basStock);
        return getDataTable( viewStockStatisticsService.selectStockList(basStock));
    }


    /**
     * 导出库存统计列表
     */
    @RequiresPermissions("search:viewstockstatistic:export")
    @Log(title = "库存统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewStockStatistics viewStockStatistics)
    {
        List<ViewStockStatistics> list = viewStockStatisticsService.selectViewStockStatisticsList(viewStockStatistics);
        ExcelUtil<ViewStockStatistics> util = new ExcelUtil<ViewStockStatistics>(ViewStockStatistics.class);
        return util.exportExcel(list, "viewstockstatistic");
    }

    /**
     * 新增库存统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存统计
     */
    @RequiresPermissions("search:viewstockstatistic:add")
    @Log(title = "库存统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewStockStatistics viewStockStatistics)
    {
        return toAjax(viewStockStatisticsService.insertViewStockStatistics(viewStockStatistics));
    }

    /**
     * 修改库存统计
     */
    @GetMapping("/edit/{warehouseCode}")
    public String edit(@PathVariable("warehouseCode") String warehouseCode, ModelMap mmap)
    {
        ViewStockStatistics viewStockStatistics = viewStockStatisticsService.selectViewStockStatisticsById(warehouseCode);
        mmap.put("viewStockStatistics", viewStockStatistics);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存统计
     */
    @RequiresPermissions("search:viewstockstatistic:edit")
    @Log(title = "库存统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewStockStatistics viewStockStatistics)
    {
        return toAjax(viewStockStatisticsService.updateViewStockStatistics(viewStockStatistics));
    }

    /**
     * 删除库存统计
     */
    @RequiresPermissions("search:viewstockstatistic:remove")
    @Log(title = "库存统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewStockStatisticsService.deleteViewStockStatisticsByIds(ids));
    }
}
